﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using FriendAnalyzer.Infrastructure.MachineLearning.Model;
using FriendAnalyzer.Infrastructure.MachineLearning.Analysis;

namespace FriendAnalyzer.Infrastructure.MachineLearning.Tests
{
    [TestClass]
    public class FacebookUserClassifierTests
    {
        private UserFeatures[] database; 
        private FacebookUserClassifier userClassifier;
        private Dictionary<UserFeatures, UserFeatures[]> groupedUsers;

        [TestInitialize]
        public void SetUp()
        {
            database = new UserFeatures[] {
                new UserFeatures 
                {
                    UserId = 1,
                    Features = new double[] { 2, 3 },
                },
                new UserFeatures 
                {
                    UserId = 2,
                    Features = new double[] { 3, 4 },
                },
                new UserFeatures 
                {
                    UserId = 3,
                    Features = new double[] { 15, 14 },
                },
                new UserFeatures 
                {
                    UserId = 4,
                    Features = new double[] { 14, 15 },
                },
                new UserFeatures 
                {
                    UserId = 5,
                    Features = new double[] { 16, 17 },
                },
                new UserFeatures 
                {
                    UserId = 6,
                    Features = new double[] { 18, 19 },
                },
                new UserFeatures 
                {
                    UserId = 7,
                    Features = new double[] { 20, 19 },
                },
                new UserFeatures 
                {
                    UserId = 8,
                    Features = new double[] { 16, 19 },
                }
            };

            userClassifier = FacebookDataAnalyzer.Instance.GetUserClassifier(database, 2, 0.0000002, 2, 100, true);

            userClassifier.Compute(true);

            groupedUsers = userClassifier.GetGroupedUsers();
        }

        [TestMethod]
        public void TwoClassClassificationTest()
        {
            Assert.AreEqual(groupedUsers.Keys.Count, 2);
        }

        [TestMethod]
        public void OnlyTwoMembersIntoOneClusterTest()
        {
            Assert.IsTrue(groupedUsers.Values.ElementAt(0).Count() == 2 || groupedUsers.Values.ElementAt(1).Count() == 2);
        }
    }
}
